package com.stefanie.study.test;

import com.stefanie.study.afp.AbstractProductA;
import com.stefanie.study.afp.AbstractProductB;
import com.stefanie.study.afp.ConcreteFactoryA;
import com.stefanie.study.afp.ConcreteFactoryB;
import com.stefanie.study.bp.Builder;
import com.stefanie.study.bp.ConcreateBuilder;
import com.stefanie.study.bp.Director;
import com.stefanie.study.sfp.Factory;
import com.stefanie.study.sfp.Product;
import com.stefanie.study.sfp.ProductOr;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: stefanie-zy
 * @time: 2024/6/26-15:20
 * @description:
 */
@RestController
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/product")
public class ProductApi {

    private final ConcreteFactoryA concreteFactoryA;
    private final ConcreteFactoryB concreteFactoryB;

    @GetMapping(value = "/sfp1")
    public void sp1() {
        Product productA = Factory.getProduct("A");
        productA.methodSame();
        productA.methodDiff();
        Product productB = Factory.getProduct("B");
        productB.methodSame();
        productB.methodDiff();
        log.info("工厂类：A商品名称{}", productA.getSku() + productA.getName());
        log.info("工厂类：B商品名称{}", productB.getSku() + productB.getName());
    }

    @GetMapping(value = "/sfp2")
    public void sp2() {
        Product productA = ProductOr.getProduct("A");
        productA.methodSame();
        productA.methodDiff();
        log.info("工厂类：A商品名称{}", productA.getSku() + productA.getName());
    }

    @GetMapping(value = "/fp1")
    public void fp1() {
//        ConcreteFactoryA concreteFactoryA = new ConcreteFactoryA();
//        com.stefanie.study.fp.Product productA = concreteFactoryA.create();
//        log.info("工厂模式：商品名称{}", productA.getSku() + productA.getName());
//        ConcreteFactoryB concreteFactoryB = new ConcreteFactoryB();
//        com.stefanie.study.fp.Product productB = concreteFactoryB.create();
//        log.info("工厂模式：商品名称{}", productB.getSku() + productB.getName());
    }

    @GetMapping(value = "/afp1")
    public void afp1() {
        AbstractProductA productA = concreteFactoryA.createProductA();
        AbstractProductB productB = concreteFactoryA.createProductB();
        AbstractProductA productC = concreteFactoryB.createProductA();
        AbstractProductB productD = concreteFactoryB.createProductB();
        log.info("A-名称：{}；B-名称：{}；C-名称：{}；D-名称：{}", productA.getName(), productB.getName(), productC.getName(), productD.getName());
    }

    @GetMapping(value = "/bp1")
    public void bp1() {
        Builder builder = new ConcreateBuilder();
        Director director = new Director(builder);
        final com.stefanie.study.bp.Product construct = director.construct();
        log.info("产品属性：A-{};B-{};C-{};D-{}", construct.getPartA(), construct.getPartB(), construct.getPartC(), construct.getPartD());
    }

}
